
package net.vinote.smart.platform.jndi;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
import javax.naming.spi.ObjectFactory;

public class PlatformContextFactory implements ObjectFactory,
		InitialContextFactory
{
	/**
	 * Initial context.
	 */
	protected static volatile Context initialContext = null;

	public static final String MAIN = "initialContext";

	@Override
	public Context getInitialContext(Hashtable<?, ?> environment)
			throws NamingException
	{
		if (initialContext == null)
		{
			synchronized (PlatformContextFactory.class)
			{
				if (initialContext == null)
				{
					initialContext = new PlatformContext(
							(Hashtable<String, Object>) environment, MAIN);
				}
			}
		}
		return initialContext;
	}

	@Override
	public Object getObjectInstance(Object obj, Name name, Context nameCtx,
			Hashtable<?, ?> environment) throws Exception
	{
		return null;
	}

}
